package com.syh.jn.scm.service.impl.operation.financial;

import com.alibaba.dubbo.config.annotation.Service;
import com.syh.core.ddd.infrastructure.repository.AggregateRepository;
import com.syh.core.ddd.service.AbstractServiceImpl;
import com.syh.jn.scm.domain.operation.entity.financial.FinancialContact;
import com.syh.jn.scm.domain.operation.repository.financial.FinancialContactRepository;
import com.syh.jn.scm.dto.operation.financial.FinancialContactMto;
import com.syh.jn.scm.dto.operation.financial.FinancialContactVo;
import com.syh.jn.scm.service.api.operation.financial.FinancialContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class FinancialContactImpl extends AbstractServiceImpl<Object, FinancialContactMto, FinancialContactVo, FinancialContact, Long> implements FinancialContactService {
  @Autowired
  private FinancialContactRepository financialContactRepository;

  @Override
  protected AggregateRepository<FinancialContact, Long> getAggregateRepository() {
    return financialContactRepository;
  }

  /**
   * 修改合作关系
   *
   * @param mto
   */
  @Override
  public void update(FinancialContactMto mto) {
    FinancialContact financialContact = financialContactRepository.getById(mto.getId());
    financialContact.modify(mto);
    financialContactRepository.update(financialContact);
  }

  /**
   * 删除合作关系
   *
   * @param id
   */
  @Override
  public void delete(Long id) {
    FinancialContact financialContact = financialContactRepository.getById(id);
    financialContact.destroy();
    financialContactRepository.remove(financialContact);
  }

  /**
   * 开启合作
   *
   * @param id
   * @return
   */
  @Override
  public Boolean enabled(Long id) {
    FinancialContact financialContact = financialContactRepository.getById(id);
    financialContact.inCooperating();
    return financialContactRepository.enabled(financialContact);
  }

  /**
   * 暂停合作
   *
   * @param id
   * @return
   */
  @Override
  public Boolean disabled(Long id) {
    FinancialContact financialContact = financialContactRepository.getById(id);
    financialContact.suspendCooperation();
    return financialContactRepository.disabled(financialContact);
  }
}
